<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/admin_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--semantic-ui的cdn引入-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <!--引入Editor_md的css-->
    <link rel="stylesheet" href="..\..\static\lib\Editor_md\css\editormd.min.css">
</head>
<body>

    <!--导航部分-->
    <nav th:replace="admin/admin_fragments ::menu" class="ui inverted attached segment">
        <div class="container">
            <div class="ui inverted stackable menu">
                
                <h2 class="ui teal header item m-padding-up-dowm-min">后台管理</h2>

                <a href="" class="item"><i class="home icon"></i>博客</a>

                <a href="" class="item"><i class="edit icon"></i>分类</a>

                <a href="" class="item"><i class="tags icon"></i>标签</a>

                <!--头像栏-->
                <div class="right menu">
                    <div class="ui dropdown item">
                        <div class="text">
                            <i class="user icon"></i>
                            lgb
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </nav>
    <!--二级导航-->
    <div th:replace="admin/admin_fragments ::secondary_menu(2)" class="ui attached pointing menu">
        <div class="container">
            <a href="#" class="active item">发布</a>
            <a href="#" class="item">列表</a>
        </div>
    </div>


    <!--中间内容-->
    <div class="m-footer-padding-up-dowm-min">
        <div class="ui container">
            <form id="blog-form" action="#" th:object="${blog}" th:action="@{/admin/blog_manage}" method="post" class="ui form">

                <!--隐含域-->
                <input type="hidden" name="published">
                <input type="hidden" name="id" th:value="*{id}">

                <!--文章标题-->
                <div class="required field">
                    <div class="ui left labeled input">
                        <div class="ui selection compact basic dropdown label">
                            <input type="hidden" value="原创">
                            <i class="dropdown icon"></i>
                            <div class="default text"></div>
                            <!--隐含域-->
                            <input type="hidden" name="flag" th:value="*{flag}">
                            <div class="menu">
                                <div class="item" data-value = "原创">原创</div>
                                <div class="item" data-value = "转载">转载</div>
                            </div>
                        </div>
                        <input type="text" name="title" placeholder="文章标题" th:value="*{title}">
                    </div>
                </div>

                <!--文章内容-->
                <div class="required field">
                    <div id="md-content" style="z-index: 1 !important;">
                        <textarea placeholder="博客内容" name="content" th:text="*{content}"></textarea>
                    </div>
                </div>

                <!--分类and标签-->
                <div class="two fields">

                    <!--分类-->
                    <div class="required field">
                        <div class="ui left labeled input">
                            <label class="ui compact teal basic label">分类</label>
                            <div class="ui fluid selection dropdown">
                                <!-- th:value="*{type.name}会出错，在新增时，type为null，不存在name,这里采用三元运算符解决 -->
                                <input type="hidden" name="type.id" th:value="*{type} != null ? *{type.id} : '' ">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div class="item" th:each="type : ${types}" th:data-value = "${type.id}" th:text="${type.name}">错误日志</div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!--标签-->
                    <div class="required field">
                        <div class="ui left labeled input">
                            <label class="ui teal basic label">图片</label>
                            <!--可以作成文件上传-->
                            <input type="text" name="picture" placeholder="图片引用地址" th:value="*{picture}">
                        </div>
                    </div>

                </div>

                <!-- 博客描述 -->
                <div class="required field">
                    <textarea name="description" placeholder="博客描述" maxlength="200" th:text="*{description}"></textarea>
                </div>

                <!-- 各个checkbox -->
                <div class="inline fields">
                    <div class="field">

                        <!--是否推荐-->
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommend" name="recommend" checked th:checked="*{recommend}">
                            <label for="recommend">推荐</label>
                        </div>

                        <!--转载说明-->
                        <div class="ui checkbox">
                            <input type="checkbox" id="shareinfo" name="shareStatement" th:checked="*{recommend}">
                            <label for="shareinfo">转载说明</label>
                        </div>

                        <!--是否赞赏-->
                        <div class="ui checkbox">
                            <input type="checkbox" id="application" name="application" th:checked="*{appreciation}">
                            <label for="application">赞赏</label>
                        </div>

                        <!--是否打开留言-->
                        <div class="ui checkbox">
                            <input type="checkbox" id="comment" name="commentable" value="hidden" th:checked="*{commentables}">
                            <label for="comment">是否打开留言</label>
                        </div>

                    </div>
                </div>

                <!--表单验证信息 默认在ui error message里提示-->
                <div class="ui error message"></div>

                <!--三个按钮-->
                <div class="ui right aligned container">
                    <!--返回上一个页面-->
                    <button type="button" class="ui basic button" onclick="window.history.go(-1)">返回</button>
                
                    <!--返回上一个页面-->
                    <button type="button" id="save_btn" class="ui basic button">保存</button>
                
                    <!--返回上一个页面-->
                    <button type="button" id="publish_btn" class="ui basic button">发布</button>
                </div>

            </form>
        </div>
    </div>

    <!--底部footer-->
    <footer th:replace="admin/admin_fragments ::footer" class="ui inverted center aligned vertical segment m-footer-padding-up-dowm-min">
        <div class="container">
            <!--grid:横向分成16份,底下的元素为3+3+3+7-->
            <div class="ui divided  inverted grid">

                <div class="three wide column">
                    <h4 class="ui inverted header">二维码</h4>
                    <img src="..\..\static\images\二维码.png"  style="width: 80px;">
                </div>

                <div class="three wide column">
                    <h4 class="ui inverted header">个人博客</h4>
                    <div class="ui inverted list link">
                        <a href="#" class="item">1.0 xxx</a>
                        <a href="#" class="item">2.0 xxx</a>
                        <a href="#" class="item">3.0 xxx</a>
                    </div>
                </div>

                <div class="three wide column">
                    <h4 class="ui inverted header">联系我</h4>
                    <div class="ui inverted list link">
                        <a href="#" class="item">微信:13776710591</a>
                        <a href="#" class="item">QQ:2899847639</a>
                        <a href="#" class="item">GitHub:xxxxxxx</a>
                    </div>
                </div>

                <div class="seven wide column">
                    <h4 class="ui inverted header">个人博客</h4>
                    <p>
                        emmm,你要说点什么
                    </p>
                </div>
            </div>

            <!--一条线-->
            <div class="ui inverted section divider"></div>
            <p>emmm,你要说点什么</p>

        </div>
    </footer>

    <!--引入jquery和semantic-ui-->
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
    <!--引入Editor_md的js-->
    <script src="..\..\static/lib/Editor_md/editormd.min.js" th:src="@{/lib/Editor_md/editormd.min.js}"></script>
    <script>
        //下拉的使用
        $('.ui.dropdown').dropdown({
            on:'hover'
        });

        //表单验证
        $('.ui.form').form({
            fields:{
                //title部分
                title:{
                    //和name保存一致
                    identifier:'title',
                    //规则
                    rules:[{
                        type:'empty',
                        prompt:'请输入文章标题'
                    }]
                },
                //content部分
                content:{
                    //和name保存一致
                    identifier:'content',
                    //规则
                    rules:[{
                        type:'empty',
                        prompt:'请输入文章内容'
                    }]
                },
                //title部分
                typeId:{
                    //和name保存一致
                    identifier:'type.id',
                    //规则
                    rules:[{
                        type:'empty',
                        prompt:'请输入文章分类'
                    }]
                },
                //picture部分
                picture:{
                    //和name保存一致
                    identifier:'picture',
                    //规则
                    rules:[{
                        type:'empty',
                        prompt:'请输入图片地址'
                    }]
                },
                //description部分
                description:{
                    //和name保存一致
                    identifier:'description',
                    //规则
                    rules:[{
                        type:'empty',
                        prompt:'请输入博客描述'
                    }]
                }
            }
        })

        //Editor_md的js,初始化markdown编辑器
        var contentEditor;
        $(function() {
            contentEditor = editormd("md-content", {
                //宽度
                width   : "100%",
                height  : 640,
                syncScrolling : "single",
                //路径
                path: "/lib/Editor_md/lib/"
            });
        });

        //保存
        $('#save_btn').click(function (){
            //将隐含域published的值赋为false
            $('[name = "published"]') .val(false);
            //提交form
            $('#blog-form').submit();
        })

        //发布
        $('#publish_btn').click(function (){
            //将隐含域published的值赋为false
            $('[name = "published"]') .val(true);
            //提交form
            $('#blog-form').submit();
        })
    </script>
</body>

<style>
    /*semantic-ui注释覆盖需要加important*/

    /*用于调整导航上下边距*/
    .m-padding-up-dowm-min{
        padding-top: 0.2em !important;
        padding-bottom: 0.2em !important;
    }

    /*用于调整footer的上下边距*/
    .m-footer-padding-up-dowm-min{
        padding-top: 5em !important;
        padding-bottom: 5em !important;
    }

    /*在一行内显示*/
    .m-inline-block{
        display: inline-block !important;
    }
</style>
</html>